<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>main</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" type="text/css" href="../css/mui.css"/>
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			.mui-bar-tab .mui-tab-item.mui-active{
				color:#ff8b3c;
			}
			.homepic{
				background: url(../img/home/01.png) no-repeat;
				background-size: 70%;
				background-position: center;
			}
			.homepic.mui-active{
				background: url(../img/home/02.png) no-repeat;
				background-size: 70%;
				background-position: center;
			}
		</style>
	</head>

	<body>
		<nav class="mui-bar mui-bar-tab">
			<a id="defaultTab" class="mui-tab-item" href="tab-webview-subpage-positioning.html">
				<span class="mui-tab-label">定位</span>
			</a>
			<a id="tixiangTab" class="mui-tab-item" href="tab-webview-subpage-remind.html">
				<span class="mui-tab-label">提醒</span>
			</a>
			<a class="mui-tab-item  homepic  mui-active" href="tab-webview-subpage-home.html">
				<span class="mui-tab-label">&nbsp;&nbsp;&nbsp;</span>
			</a>
			<a class="mui-tab-item" href="tab-webview-subpage-service.html">
				<span class="mui-tab-label">服务</span>
			</a>
			<a class="mui-tab-item" href="tab-webview-subpage-mine.html">
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>
		<script src="../js/mui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
			 //mui初始化
			mui.init();
			var subpages = ['tab-webview-subpage-positioning.html', 'tab-webview-subpage-remind.html','tab-webview-subpage-home.html', 'tab-webview-subpage-service.html', 'tab-webview-subpage-mine.html'];
			var subpage_style = {
				top: '0px',
				bottom: '51px'
			};
			
			var aniShow = {};
			
			 //创建子页面，首个选项卡页面显示，其它均隐藏；
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();//获取当前窗口的WebviewObject对象
				for (var i = 0; i < 5; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);//创建新的Webview窗口
					if (i != 2) {
						sub.hide();//隐藏Webview窗口
					}else{
						temp[subpages[i]] = "true";
						mui.extend(aniShow,temp);//将两个对象合并成一个对象。
					}
					self.append(sub);//在Webview窗口中添加子窗口
				}
			});
			 //当前激活选项
			var activeTab = subpages[2];
			//var title = document.getElementById("title");
			 //选项卡点击事件
			mui('.mui-bar-tab').on('tap', 'a', function(e) {
				var targetTab = this.getAttribute('href');
				if (targetTab == activeTab) {
					return;
				}
				//更换标题
				//title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
				//显示目标选项卡
				//若为iOS平台或非首次显示，则直接显示
				if(mui.os.ios||aniShow[targetTab]){
					plus.webview.show(targetTab);
				}else{
					//否则，使用fade-in动画，且保存变量
					var temp = {};
					temp[targetTab] = "true";
					mui.extend(aniShow,temp);
					plus.webview.show(targetTab,"fade-in",300);
				}
				//隐藏当前;
				plus.webview.hide(activeTab);
				//更改当前活跃的选项卡
				activeTab = targetTab;
			});
			
			 //自定义事件，模拟点击“定位选项卡”
			document.addEventListener('gohome', function() {
				var defaultTab = document.getElementById("defaultTab");
				//模拟首页点击
				mui.trigger(defaultTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if (defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
			});
			//自定义事件，模拟点击“提醒选项卡”
			document.addEventListener('gotixing', function() {
				var tixiangTab = document.getElementById("tixiangTab");
				//模拟首页点击
				mui.trigger(tixiangTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if (defaultTab !== current) {
					current.classList.remove('mui-active');
					tixiangTab.classList.add('mui-active');
				}
			});
		</script>
	</body>

</html>